package org.line.common.protocol;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.handler.timeout.IdleStateHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * 心跳检测
 *
 * @author moqishu
 * */
public class IdleCheckHandler extends IdleStateHandler {

    public static final int USER_CHANNEL_READ_IDLE_TIME =1200;

    public static final int READ_IDLE_TIME =60;

    public static final int WRITE_IDLE_TIME =40;

    private static Logger logger = LoggerFactory.getLogger(IdleCheckHandler.class);


    public IdleCheckHandler(int readerIdleTimeSeconds, int writerIdleTimeSeconds, int allIdleTimeSeconds) {
        super(readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds);
    }

    @Override
    protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception {
        if (IdleStateEvent.FIRST_ALL_IDLE_STATE_EVENT == evt) {
            logger.info("channel write timeout {}",ctx.channel());

        }

        super.channelIdle(ctx, evt);
    }


}
